<script setup lang="ts">
/**
 * 验证link按钮
 * 可以通过传入auth-tag(按钮权限标识)自动渲染
 * 按钮的图标 名称 禁用状态 显示状态
 */
import { authMenuHandle, getMenuHandleData, saveHandleKey } from '@/util/menu'
import { icon } from '@/util/icons'
import { onMounted } from 'vue'

/**
 * authTag :权限标识
 * disabled : 禁用状态
 * authShow : 在无权限的时候的显示状态
 */
const props = defineProps<{
  authTag?: string
  authShow?: boolean
  disabled?: boolean
}>()
onMounted(() => {
  if (props.authTag) {
    saveHandleKey(props.authTag)
  }
})
/* 初始化按钮信息 */
const buttonInfo = getMenuHandleData(props.authTag || '')
</script>
<template>
  <el-link
    v-if="buttonInfo.show == '1' && (authMenuHandle(buttonInfo.tag!) || authShow)"
    :disabled="disabled || buttonInfo?.status == '0' || !authMenuHandle(buttonInfo.tag!)"
    :icon="buttonInfo.iconType == 'sys' ? (icon as any)[buttonInfo?.icon!] : ''"
    :type="buttonInfo.type"
  >
    <slot>{{ buttonInfo.name }}</slot>
  </el-link>
</template>
